--pieces
local base = piece("base")
  body = piece("body") 
    local engine1, engine2 = piece("engine1", "engine2")
    local turret, sleeve = piece("turret", "sleeve1")
      local barrel1a, firepoint1a = piece("barrel1a", "firepoint1a")  
      local barrel1b, firepoint1b = piece("barrel1b", "firepoint1b")	
      local machinegun1, firepoint2 = piece("machinegun1", "firepoint2")
	--local cover1down, cover1up = piece("cover1down", "cover1up")
      local machinegun2, firepoint3 = piece("machinegun2", "firepoint3")
	--local cover2down, cover2up = piece("cover2down", "cover2up")

scriptParams = {
  smokePieces = { body },
  enginePieces = { engine1, engine2 },
  smokeDelay = 200,
  maxRockAngleX = 5,
  maxRockAngleZ = 5,
  rockOnMove = true,

  weapons = {
    [1] = {
      turretTurnSpeed = 40,
      sleeveTurnSpeed = 30,
	    barrelRecoil = 3,
	    rockForce = 400,
	    minPitch = -20,
	    --cegID = 1,
	    restores = true,
      --restoreDelay = 3000,
      --openAnimation = true,	  
    },
    [2] = {	
      turretTurnSpeed = 180,
      sleeveTurnSpeed = 180,
	    minPitch = -20,
    },
    [3] = {	
      turretTurnSpeed = 180,
      sleeveTurnSpeed = 180,
	    minPitch = -20,
    },		
  }  
}

include "pre_scripts.lua"

setWeaponPieces(1, turret, sleeve, { barrel1a, barrel1b }, { firepoint1a, firepoint1b })
setWeaponPieces(2, machinegun1, machinegun1, machinegun1, firepoint2)
setWeaponPieces(3, machinegun2, machinegun2, machinegun2, firepoint3)

include "scripts.lua"


function script.Killed (recentDamage, maxHealth)
  local severity = recentDamage / maxHealth
  
  Explode (engine1, SFX.NONE)
  Explode (engine2, SFX.NONE)
  Explode (firepoint1a, SFX.NONE)
  Explode (firepoint1b, SFX.NONE)  
  Explode (firepoint2, SFX.NONE)
  Explode (firepoint3, SFX.NONE)  
  if (severity <= 0.25) then
    Explode (body, SFX.NONE)
    Explode (turret, SFX.NONE)
    Explode (sleeve, SFX.NONE)
    Explode (barrel1a, SFX.NONE)
    Explode (barrel1b, SFX.NONE)	
    Explode (machinegun1, SFX.FALL)
    Explode (machinegun2, SFX.FALL) 	
	  return 1
  elseif (severity <= 0.50) then
    Explode (body, SFX.NONE)
    Explode (turret, SFX.NONE)
    Explode (sleeve, SFX.SMOKE + SFX.FIRE)  --SFX.NONE
    Explode (barrel1a, SFX.SMOKE + SFX.FIRE)
    Explode (barrel1b, SFX.SMOKE + SFX.FIRE)
    Explode (machinegun1, SFX.SMOKE + SFX.FIRE)
	  Explode (machinegun2, SFX.SMOKE + SFX.FIRE)	
	  return 2
  else
    Explode (body, SFX.SHATTER)
    Explode (turret, SFX.SHATTER)
    Explode (sleeve, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)  --SFX.SHATTER
    Explode (barrel1a, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (barrel1b, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (machinegun1, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (machinegun2, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)	
	  return 3
  end
end